﻿using ArtMath.Attribute;
using ArtMath.Component.Manager;
using ArtMath.Core.Helper;
using ArtMath.Setting;
using System;
using System.ComponentModel;
using System.Drawing;

namespace ArtMath.Component.Point
{
    /// <summary>
    /// 交点基类
    /// </summary>
    [Serializable]
    public abstract class CrossoverPointBase : ConstructedPointBase
    {
        CrossoverPointsManagerBase mgr;
        public CrossoverPointBase(SketchPad pad, string name, LineBase line1, LineBase line2, CrossoverPointsManagerBase mgr = null, bool addToList = true) : base(pad, name, ToolTypeName.jd, addToList)
        {
            this.mgr = mgr;
            OutlineColor = Settings.Instance.CrossoverPointOutlineColor;
            FillColor = Settings.Instance.CrossoverPointFillColor;
            OutHosts = new LineBase[2];
            Line1 = line1;
            Line2 = line2;
        }
        [DefaultValue(typeof(Color), "175, 95, 60")]
        public override Color OutlineColor
        {
            get
            {
                return base.OutlineColor;
            }

            set
            {
                base.OutlineColor = value;
            }
        }
        [DefaultValue(typeof(Color), "251, 150, 110")]
        public override Color FillColor
        {
            get
            {
                return base.FillColor;
            }

            set
            {
                base.FillColor = value;
            }
        }
        [MultilingualCategory("Structure"), MultilingualDisplayName("{0}1", "Line")]
        public LineBase Line1
        {
            get { return OutHosts[0]; }
            set { SetLine(0, value); }
        }
        [MultilingualCategory("Structure"), MultilingualDisplayName("{0}2", "Line")]
        public LineBase Line2
        {
            get { return OutHosts[1]; }
            set { SetLine(1, value); }
        }
        public override string Name
        {
            get
            {
                return base.Name;
            }

            set
            {
                CrossoverPointsManager_A ca = mgr as CrossoverPointsManager_A;
                if (ca != null)
                {
                    if (!string.IsNullOrEmpty(value))
                    {
                        if (ca.CheckPointNameExist(value))
                        {
                            value = Utility.GetNextAvailableName(value, ca.CheckPointNameExist);
                        }
                    }
                }
                base.Name = value;
            }
        }
        //public override bool Movable
        //{
        //    get
        //    {
        //        return Deleted || Pad.OperatingPoint.Count > 0 && mgr.Points.Contains(Pad.OperatingPoint.Peek()) && moveLockedAllFalse;
        //    }
        //}
        public override ComponentManagerBase ComponentManager
        {
            get { return mgr; }
        }
        public override void ConvertType(ToolTypeName targetType)
        {
            if (targetType != ToolType) return;
            CrossoverPointBase targetPoint = null;
            SimulateDeleted(() =>
            {
                if (Pad.CoordinateType == CoordinateSystemType.PolarCoordinate)
                {
                    targetPoint = new PCrossoverPoint(Pad, Name, Line1, Line2, mgr, false);
                }
                else
                {
                    targetPoint = new RCrossoverPoint(Pad, Name, Line1, Line2, mgr, false);
                }
            });
            afterGenerateNewType(targetPoint);
        }
    }
}
